package com.ftg.learn.chapter05;

import java.util.Arrays;

/**
 * @author kangjx
 * @date 2022/12/19
 */
public class Four {

    public static void main(String[] args) {
        int[] newArray = {23,4,6,11,8,2};
        // 循环数组  把最大的放到后面 多少级，比数组长度小一次
        for(int i = 0,len = newArray.length - 1;i < len;i++){

            for(int j = 0;j < newArray.length - 1 - i;j++){
                if(newArray[j] > newArray[j + 1]){
                    //交换
                    int temp = newArray[j];
                    //这一行出错越界
                    newArray[j] =  newArray[j + 1];
                    newArray[j + 1] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(newArray));
    }

}
